#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	char s[110];
	scanf("%d",&n);
	while(n--)
	{
		int maxn = 0;
		int cnt = 0;
		int len;
		scanf(" %d",&len);
		scanf(" %s",s);
		for(int i = len-1;i>=0;i--)
		{
			if(s[i]=='P')
			{
				cnt++;
				//printf("****%d\n",cnt);
			}
			else 
			{
				if(cnt>maxn)
				{
					maxn = cnt;
					//cnt = 0;
				}
				cnt = 0;
			}
		}
		printf("%d\n",maxn);
	}
} 
